package com.bluemsun.naturallanguageprocessing.controller;

import com.bluemsun.naturallanguageprocessing.common.ResponseCode;
import com.bluemsun.naturallanguageprocessing.common.ServerResponse;
import com.bluemsun.naturallanguageprocessing.entity.Classify;
import com.bluemsun.naturallanguageprocessing.service.IClassifyService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/classify")
public class ClassifyController {

    @Resource
    private IClassifyService classifyService;

    @GetMapping(value = "/get")
    public ServerResponse<Object> getClassify(){
        return classifyService.getClassify();
    }

    @PostMapping(value = "/delete/{id}")
    public ServerResponse<Object> deleteClassify(@PathVariable Integer id){
        return classifyService.deleteClassify(id);
    }

    @PostMapping(value = "/add")
    public ServerResponse<Object> addClassify(@RequestBody Classify classify){
        if (classify!=null && !StringUtils.isEmpty(classify.getClassify())){
            return classifyService.insertClassify(classify);
        }else {
            return ServerResponse.createByErrorCodeMessage(-1,"添加类别失败");
        }
    }

    @PostMapping(value = "/update")
    public ServerResponse<Object> updateClassify(@RequestBody Classify classify){
        if (classify!=null && !StringUtils.isEmpty(classify.getClassify())){
            return classifyService.updateClassify(classify);
        }else {
            return ServerResponse.createByErrorCodeMessage(-1,"修改类别失败");
        }
    }
}
